package com.zsummer.demo.cloudgateway;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author zsummer
 * @since 2022/2/13
 * 实现自定义网关过滤器
 */
@Component
public class CustomerFilter implements GlobalFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        System.out.println("开始打印日志");
        Mono<Void> filter = chain.filter(exchange);
        System.out.println("结束打印日志");
        return filter;
    }

    @Override
    public int getOrder() {
        return -1;
    }
}
